<template>
  <div class="contain">
    <div class="contain-header">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>综合查询</el-breadcrumb-item>
        <el-breadcrumb-item>医生信息查询</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="contain-body">
      <div class="body-header">
        <el-form :inline="true" size="mini">
          <el-form-item label="所属医院">
            <el-select placeholder="请选择所属医院" v-model="page.hospitalName">
              <el-option :label="item.name" :value="item.name" v-for="item in hospitalList" :key="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="所属科室">
            <el-select placeholder="请选择所属科室" v-model="page.administrativeOfficeName">
              <el-option :label="item.name" :value="item.name" v-for="item in officeList" :key="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="所属地区">
            <el-select placeholder="请选择所属地区" v-model="page.provinceName">
              <el-option :label="item.name" :value="item.name" v-for="item in provinceList" :key="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="findDoctorInfo">查 询</el-button>
            <el-button type="primary" icon="el-icon-refresh" @click="reset">刷 新</el-button>
            <el-button type="primary" icon="el-icon-download" @click="downLoad">导 出</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="body-table">
        <el-table
            :data="tableData"
            style="width: 100%">
          <el-table-column
              type="index"
              label="序号"
              width="50px"
              align="center"
          >
          </el-table-column>
          <el-table-column
              prop="realName"
              label="医生姓名"
              align="center"
          >
          </el-table-column>
          <el-table-column
              prop="telPhone"
              label="注册手机号"
              align="center"
          >
          </el-table-column>

          <el-table-column
              prop="hospital"
              label="所属医院"
              align="center"
          >
          </el-table-column>
          <el-table-column
              prop="administrativeOffice"
              label="所属科室"
              align="center"
          >
          </el-table-column>
          <el-table-column
              prop="provinceName"
              label="所属地区"
              align="center"
          >
          </el-table-column>
          <el-table-column
              prop="createTime"
              label="注册时间"
              align="center"
          >
          </el-table-column>
        </el-table>
      </div>
      <div class="body-page">
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page.pageIndex"
            :page-sizes="[10, 15, 20, 25]"
            :page-size="page.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      provinceList: [],
      hospitalList: [],
      officeList: [],
      page: {
        pageIndex: 1,
        pageSize: 10,
        provinceName: null,
        hospitalName: null,
        administrativeOfficeName: null
      },
      total: 0
    }
  },
  created() {
    this.findDoctorInfo()
    this.findAllProvince()
    this.findAllHospital()
    this.findAllAdministrativeOffice()
  },
  methods: {
    downLoad() {
        this.$confirm('确定导出全部数据吗, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.axios.post('/admin-data-statistics/downLoadDoctorInfo', this.page, {
            responseType: "blob",
          }).then(res => {
            const blob = new Blob([res.data], {type: "application/vnd.ms-excel"});
            const url = window.URL.createObjectURL(blob);
            let a = document.createElement('a');
            a.download = '医生信息.xlsx';
            a.href = url;
            a.click();
            if (res.data) {
              this.$message.success('导出数据成功');
            }
          })
        })
    },
    reset() {
      this.page.pageIndex = 1
      this.page.pageSize = 10
      this.page.provinceName = null
      this.page.hospitalName = null
      this.page.administrativeOfficeName = null
      this.findDoctorInfo()
    },
    findDoctorInfo() {
      this.axios.post('/admin-doctor/findDoctorInfo', this.page).then(res => {
        if (res.data.code === 200) {
          this.tableData = res.data.data.data
          this.total = res.data.data.total
        }
      })
    },
    findAllProvince() {
      this.axios.post('/admin-province/findAllProvince').then(res => {
        if (res.data.code === 200) {
          this.provinceList = res.data.data
        }
      })
    },
    findAllHospital() {
      this.axios.post('/admin-hospital/findAllHospital').then(res => {
        if (res.data.code === 200) {
          this.hospitalList = res.data.data
        }
      })
    },
    findAllAdministrativeOffice() {
      this.axios.post('/admin-administrative-office/findAllAdministrativeOffice').then(res => {
        if (res.data.code === 200) {
          this.officeList = res.data.data
        }
      })
    },
    handleSizeChange(val) {
      this.page.pageSize = val
      this.findDoctorInfo()
    },
    handleCurrentChange(val) {
      this.page.pageIndex = val
      this.findDoctorInfo()
    }
  },
}
</script>

<style scoped lang="less">
.contain {
  width: 100%;
  height: 100%;

  .contain-header {
    width: 100%;
    height: 50px;
    display: flex;
    align-items: center;
  }

  .contain-body {
    width: 100%;
    height: calc(100% - 50px);
    background-color: #fff;
    padding: 1%;
    box-sizing: border-box;

    .body-header {
      width: 100%;
      height: 50px;
    }

    .body-table {
      width: 100%;
      height: calc(100% - 120px);
    }

    .body-page {
      width: 100%;
      height: 70px;
      display: flex;
      align-items: center;
    }
  }
}
</style>
